﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoShopping.Model;

namespace GoShopping.BLL.ProfileInfo
{
    /// <summary>
    /// 用户配置信息操作类：地址信息维护
    /// </summary>
    public class AddressListBean
    {

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="al"></param>
        /// <returns></returns>
        public int AddOneAddressList(AddressList al)
        {
            return Databases.DBGoShopping.Insert(GoShoppingNBear.AddressList).AddColumn(
                GoShoppingNBear.AddressList.AcceptPeople, al.AcceptPeople).AddColumn(
                GoShoppingNBear.AddressList.AcceptPeopleTel, al.AcceptPeopleTel).AddColumn(
                GoShoppingNBear.AddressList.CityID, al.CityID).AddColumn(
                GoShoppingNBear.AddressList.CountyID, al.CountyID).AddColumn(
                GoShoppingNBear.AddressList.DetailStreet, al.DetailStreet).AddColumn(
                GoShoppingNBear.AddressList.ProvinceID, al.ProvinceID).AddColumn(
                GoShoppingNBear.AddressList.UserID, al.UserID).AddColumn(
                GoShoppingNBear.AddressList.AcceptPeopleMobileTel, al.AcceptPeopleMobileTel).AddColumn(
                GoShoppingNBear.AddressList.ZipCode, al.ZipCode).ExecuteReturnAutoIncrementID(
                GoShoppingNBear.AddressList.ID);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="addressListID"></param>
        public void DelOneAddressList(int addressListID)
        {
            Databases.DBGoShopping.Delete(GoShoppingNBear.AddressList).Where(
                GoShoppingNBear.AddressList.ID == addressListID).Execute();
        }

        /// <summary>
        /// 获取一个用户的地址列表
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public IList<AddressList> GetUserAddressList(int userid)
        {
            return Databases.DBGoShopping.Select(GoShoppingNBear.AddressList).Where(
                GoShoppingNBear.AddressList.UserID == userid).ToList<AddressList>();
        }

        /// <summary>
        /// 更新一个地址列表，根据AddressList的主键ID
        /// </summary>
        /// <param name="al"></param>
        public void Update(AddressList al)
        {
            Databases.DBGoShopping.Update(GoShoppingNBear.AddressList).AddColumn(
                GoShoppingNBear.AddressList.AcceptPeople, al.AcceptPeople).AddColumn(
                GoShoppingNBear.AddressList.AcceptPeopleTel, al.AcceptPeopleTel).AddColumn(
                GoShoppingNBear.AddressList.CityID, al.CityID).AddColumn(
                GoShoppingNBear.AddressList.CountyID, al.CountyID).AddColumn(
                GoShoppingNBear.AddressList.DetailStreet, al.DetailStreet).AddColumn(
                GoShoppingNBear.AddressList.ProvinceID, al.ProvinceID).AddColumn(
                GoShoppingNBear.AddressList.UserID, al.UserID).AddColumn(
                GoShoppingNBear.AddressList.ZipCode, al.ZipCode).AddColumn(
                GoShoppingNBear.AddressList.AcceptPeopleMobileTel, al.AcceptPeopleMobileTel).Where(
                GoShoppingNBear.AddressList.ID == al.ID).Execute();
        }
    }
}
